package com.lianxi;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author xiyu
 * @version 1.0
 * @date 2025/4/7 11:52
 * @description
 */
public class T1 {
    //合并两个文件
    public static void hebing(String srcFile,String srcFile2,String tarFile) {
        try {
            FileOutputStream fos = new FileOutputStream(tarFile);

            FileInputStream fis = new FileInputStream(srcFile);
            byte[] buff = new byte[1024];
            byte[] buff1 = new byte[1];
            int cont = fis.read(buff1);
            int len = 0;
            while ((len = fis.read(buff))!=-1){
                fos.write(buff,0,len);
            }
            fis.close();


            FileInputStream fis1 = new FileInputStream(srcFile2);
            while ((len = fis1.read(buff))!=-1){
                fos.write(buff,cont,len);
            }
            fis1.close();


            fos.close();

        } catch (FileNotFoundException e) {
//            e.printStackTrace();
            throw new RuntimeException(e);
        } catch (IOException e) {
//            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        hebing("D:\\file\\test\\0001.txt","D:\\file\\test\\0002.txt","D:\\file\\test\\0003.txt");
    }
}
